/**
 * Created by Deb on 8/26/2014.
 */
(function () {
    "use strict";

    angular
        .module("codeVerificationSystem")
        .controller("SubmissionAddCtrl",
        ["$http",
            "$uibModalInstance",
            "currentUser",
            "task",
            SubmissionAddCtrl]);


    function SubmissionAddCtrl($http, $uibModalInstance, currentUser, task) {
        var vm = this;
        vm.task = task;

        vm.addSubmission = function() {
            $http({
                method: 'POST',
                url: 'http://localhost:49616/api/submissions',
                headers: {
                    'Content-Type': 'application/json; charset=utf-8',
                    'Authorization': "Bearer " + currentUser.getProfile().token
                },
                data: { SourceCode: vm.sourceCode, TaskId: vm.task.id }
            }).then(function successCallback(response) {
                $uibModalInstance.close();
            }, function errorCallback(response) {
                console.log("losho");
            });
        };

        vm.cancel = function () {
            $uibModalInstance.dismiss();
        };
    }
}());
